package com.scan.dao.model;

import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;

public class VoteSubject {
    private Integer voteId;

    private String voteTitle;

    private Date voteStarttime;

    private Date voteEndtime;

    private Date voteSendtime;

    private String voteDescription;

    private String voteAllowview;

    private String voteAllowguest;

    private String voteSubject;

    private String voteRule;
    @JSONField(serialize = false)
    private Integer voteInterval;
    @JSONField(serialize = false)
    private Boolean voteEnabled;
    @JSONField(serialize = false)
    private Integer voteNumber;

    private String remark;

    private List<VoteOption> options;

    private int optionsCnt = 0;

    private int voteCnt = 0;


    public Integer getVoteId() {
        return voteId;
    }

    public void setVoteId(Integer voteId) {
        this.voteId = voteId;
    }

    public String getVoteTitle() {
        return voteTitle;
    }

    public void setVoteTitle(String voteTitle) {
        this.voteTitle = voteTitle;
    }

    public Date getVoteStarttime() {
        return voteStarttime;
    }

    public void setVoteStarttime(Date voteStarttime) {
        this.voteStarttime = voteStarttime;
    }

    public Date getVoteEndtime() {
        return voteEndtime;
    }

    public void setVoteEndtime(Date voteEndtime) {
        this.voteEndtime = voteEndtime;
    }

    public Date getVoteSendtime() {
        return voteSendtime;
    }

    public void setVoteSendtime(Date voteSendtime) {
        this.voteSendtime = voteSendtime;
    }

    public String getVoteDescription() {
        return voteDescription;
    }

    public void setVoteDescription(String voteDescription) {
        this.voteDescription = voteDescription;
    }

    public String getVoteAllowview() {
        return voteAllowview;
    }

    public void setVoteAllowview(String voteAllowview) {
        this.voteAllowview = voteAllowview;
    }

    public String getVoteAllowguest() {
        return voteAllowguest;
    }

    public void setVoteAllowguest(String voteAllowguest) {
        this.voteAllowguest = voteAllowguest;
    }

    public Integer getVoteInterval() {
        return voteInterval;
    }

    public void setVoteInterval(Integer voteInterval) {
        this.voteInterval = voteInterval;
    }

    public Boolean getVoteEnabled() {
        return voteEnabled;
    }

    public void setVoteEnabled(Boolean voteEnabled) {
        this.voteEnabled = voteEnabled;
    }

    public Integer getVoteNumber() {
        return voteNumber;
    }

    public void setVoteNumber(Integer voteNumber) {
        this.voteNumber = voteNumber;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public List<VoteOption> getOptions() {
        return options;
    }

    public void setOptions(List<VoteOption> options) {
        this.options = options;
    }

    public String getVoteSubject() {
        return voteSubject;
    }

    public void setVoteSubject(String voteSubject) {
        this.voteSubject = voteSubject;
    }

    public String getVoteRule() {
        return voteRule;
    }

    public void setVoteRule(String voteRule) {
        this.voteRule = voteRule;
    }

    public int getOptionsCnt() {
        if (options != null) return options.size();
        return optionsCnt;
    }

    public int getVoteCnt() {
        if (options != null) {
            Collections.sort(options, new Comparator<VoteOption>() {
                @Override
                public int compare(VoteOption o1, VoteOption o2) {
                    return o2.getVotes() - o1.getVotes();
                }
            });
            for (int i = 0, len = options.size(); i < len; i++) {
                VoteOption option = options.get(i);
                voteCnt += option.getVotes();
                option.setRank(i + 1);
            }
        }
        return voteCnt;
    }
}